package Singleto;
//  双重检验锁 基础篇 在懒汉式基础上加synchronized
// 效率降低

public class Singleto3 {
    private static Singleto3 INSTANCE;

    private Singleto3(){}
    // 加synchronized关键字 保证了操作的原子性
    public static synchronized Singleto3 getInstance(){
        if (INSTANCE == null){
            try {
                Thread.sleep(1);
            }catch (Exception e){
                e.printStackTrace();
            }
            INSTANCE = new Singleto3();
        }
        return INSTANCE;
    }
    public void m(){
        System.out.println("m");
    }

    public static void main(String[] args) {
        for(int i=1;i<100;i++){
            new Thread(()->{
                System.out.println(Singleto3.getInstance().hashCode());
            }).start();
        }
    }
}
